*table 4 of amces
	
net install lincomestadd, from("https://github.com/benzipperer/lincomestadd/raw/master")
reg outcome $mod , baselevels $ses coeflegend	
lincomestadd ( _b[3.country] *0) + ( _b[3.country] +  _b[3o.country#2o.legal_status]) *1 , statname(rom)
foreach x of numlist 2 4 5 {
   lincomestadd  (`x'.country *1/2)  + (`x'.country + `x'.country#2.legal_status) * 1/2, statname(country`x')
	}
lincomestadd ( _b[2.legal_status] *1/4) + ( _b[2.legal_status] +  _b[2.country#2.legal_status]) *1/4 + ///
                               ( _b[2.legal_status] +  _b[3o.country#2o.legal_status]) *0+ ///
							   ( _b[2.legal_status] + _b[4.country#2.legal_status]) *1/4 + ///
							   ( _b[2.legal_status] +  _b[5.country#2.legal_status]) *1/4, statname(legal)
eststo model1
esttab model1 using "tableS4.tex", keep(*.sex  *.religion  *.residence *.occupation *.education *.language *.friends  *.team_support *.children 1.country 1.legal_status) ///
cells(b(star fmt(3)) se(par fmt(2))) stats(romb romse country2b country2se  ///
country4b country4se country5b country5se legalb legalse, label("Romania" " " "China"  " " "Pakistan"  " " "Senegal" " " "Regular" " ")) alignment(D{.}{.}{-1}) replace label nolines nomtitle booktabs  

////// fixing it
est clear
reg outcome $mod , baselevels $ses coeflegend	
lincomestadd ( _b[3.country] *0) + ( _b[3.country] +  _b[3o.country#2o.legal_status]) *1 , statname(rom)
foreach x of numlist 2 4 5 {
   lincomestadd  (`x'.country *1/2)  + (`x'.country + `x'.country#2.legal_status) * 1/2, statname(country`x')
	}
lincomestadd ( _b[2.legal_status] *1/4) + ( _b[2.legal_status] +  _b[2.country#2.legal_status]) *1/4 + ///
                               ( _b[2.legal_status] +  _b[3o.country#2o.legal_status]) *0+ ///
							   ( _b[2.legal_status] + _b[4.country#2.legal_status]) *1/4 + ///
							   ( _b[2.legal_status] +  _b[5.country#2.legal_status]) *1/4, statname(legal)
eststo model1
esttab model1 using "tableS4.tex", keep(*.sex  *.religion  *.residence *.occupation *.education *.language *.friends  *.team_support *.children 1.country 1.legal_status) ///
cells(b(star fmt(3)) se(par fmt(2))) stats(romb romse country2b country2se  ///
country4b country4se country5b country5se legalb legalse, label("Romania" " " "China"  " " "Pakistan"  " " "Senegal" " " "Regular" " ")) alignment(D{.}{.}{-1}) replace label nolines nomtitle booktabs  star(* 0.10 ** 0.05 *** 0.01) ///
refcat(1.sex "Sex" 1.religion "Religion" 1.occupation "Occupation" 1.education "Education" 1.language "Italian proficiency" ///
1.friends "Best friends" 1.team_support "Team support" 1.children "Number of children" 1.country "Country of origin" 1.legal_status "Legal status" 1.residence "Length of residence", nolabel ) legend




